package com.cts.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cts.annotation.OperationLogger;
import com.cts.constant.AboutConstant;
import com.cts.entity.About;
import com.cts.model.vo.Result;
import com.cts.service.AboutService;
import com.mysql.cj.util.StringUtils;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.*;

/**
 * @projectName: CBlog
 * @package: com.cts.controller.admin
 * @className: AboutAdminController
 * @author: chentongsheng
 * @description: 后台管理 - 关于我
 * @date: 2023/2/6 15:24
 * @version: 1.0
 */

@RestController
@RequestMapping("/admin")
public class AboutAdminController {

    @Autowired
    AboutService aboutService;

    @OperationLogger("关于我查询")
    @ApiOperation("关于我查询")
    @GetMapping("/about")
    public Result getAbout(){
        Map<String, String> aboutMap = new HashMap<>();
        List<About> list = aboutService.list();
        for (About about : list) {
            aboutMap.put(about.getNameEn(), about.getValue());
        }
        return Result.ok("请求成功",aboutMap);
    }

    @OperationLogger("关于我数据更新")
    @ApiOperation("关于我数据更新")
    @PostMapping("/about")
    public Result saveAbout(@RequestBody Map<String, String> aboutMap){
        String title = aboutMap.get(AboutConstant.TITLE);
        if(StringUtils.isNullOrEmpty(title)){
            return Result.error("标题不能为空");
        }
        return aboutService.saveAbout(aboutMap);
    }
}
